import {Component, OnInit} from "@angular/core";
import {UploadFile} from "ng-zorro-antd";
import {AppUrl} from "../../../../app.url";
import {HttpClient} from "@angular/common/http";

@Component({
    templateUrl:'businessInfo.component.html',
    styleUrls: ['./businessInfo.component.less']
})

export class BusinessInfoComponent implements  OnInit{

    fileList:any=[];
    previewImage:string;
    previewVisible:boolean;

    provinceList:any=[];
    prOpt:any;//公司省份
    cityList:any=[];
    placeList:any[];
    cOpt:number;//公司所在市
    levelList:any[];//企业性质
    scaleList:any[];//企业规模列表
    switchValue:boolean;

    uploadUrl:string;


    busiInfo:any={
        realname:'',//真实姓名
        cityid:0,//所在城市区域
        busiscale:'',//企业规模
        id:0,
        userid:'',
        sex:'',//性别
        qq:'',//qq号码
        email:'',//邮箱
        addr:'',//详细地址
        businessname:'',//企业名称
        position:'',//部门名称
        busilevel:'',//企业性质
        authforview:'',//同意其他用户使用积分查看我的联系方式
        introduce:''//企业介绍
        };




    constructor(public http:HttpClient){
        let userid=localStorage.getItem('userid');
        this.http.post(AppUrl.business.busiInfo,{userid:userid}).subscribe(data=>{
            console.log(data);
            let temp:any=data;
            this.busiInfo=temp.data[0];
            this.levelList=temp.data[1];
            this.scaleList=temp.data[2];
        });

        this.uploadUrl=AppUrl.MemberHeadImg.upoadUrl;
    }

    ngOnInit(){
        this.http.post(AppUrl.place.cityUrl,{}).subscribe(data=>{
            console.log(data);
            let temp1:any;
            temp1=data;
            let temp=temp1.data;
            this.placeList=temp1.data;
            let i=1;
            this.provinceList.push({
                id:temp[0].id,
                province:temp[0].province
            });
            for(let place of temp){
                if(this.provinceList[i-1].id==place.id){
                    continue;
                }else{
                    this.provinceList.push({
                        id:place.id,
                        province:place.province
                    });
                    i++;
                }
            }
            this.prOpt=temp[0].id;
        });
    }

    handlePreview = (file: UploadFile) => {
        this.previewImage = file.url || file.thumbUrl;
        this.previewVisible = true;
    }

    submit(){
        this.busiInfo.authforview=this.switchValue?'1':'0';
        console.log(this.busiInfo);
        this.http.post(AppUrl.business.busiSave,this.busiInfo).subscribe(data=>{

        });
    }

    chooseProvince(data){
        console.log(data);
        this.cityList=this.placeList.filter(e=>e.id==data);
    }
}
